package Main;
import io.ArticleOutput;
import io.IO;
import io.suggestedListIO;

import java.io.IOException;
import java.util.List;

import wrongWordsHandling.ErrorsHandling;
import wrongWordsHandling.Replace;
import wrongWordsHandling.Suggestion;
import Data.DictionaryData;
import Data.inputArticle;
import Data.wrongWordsData;
import analyzer.Analyzer;

class Main {
	
	/**
	 * Main function
	 * @param 
	 * @throws IOException 
	 */
	public static void main(String[] args)  {	
		Analyzer analyzer = new Analyzer();
		try {
			DictionaryData.getDictionary();
		} catch(IOException e) {
			System.out.println("Read Error");
		}

		IO io = new IO();
		String article = "";
		try {
			article = io.readInput();
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			System.out.println("Read error.");
		}
		analyzer.handleInputArticle(article);
		List<String> inputList = inputArticle.getInputList();
		for(String input: inputList) {
			boolean isVocab = analyzer.modifier(input);
			if (!isVocab)
				wrongWordsData.dealWithWrongWords(input);
		}
		if (wrongWordsData.getWrongWordNumber()>0){
			System.out.println("There are " + wrongWordsData.getWrongWordNumber() + " wrong words in the input file.\n");
			System.out.println("The following are suggestion:");
			System.out.println(wrongWordsData.getWrongWord() + "\n");
			suggestedListIO list = new suggestedListIO();
			for(String wrongWord: wrongWordsData.getWrongWord()){
				Suggestion suggestion = new Suggestion();
				ErrorsHandling errorsHandling = new ErrorsHandling(suggestion);
				list.io(wrongWord, errorsHandling.suggestion(wrongWord));
			}
			int choice[] = new int[99];
			Replace replace = new Replace();
			list.menu(choice);
			article = replace.replace(article,choice);
			System.out.println(article);
			ArticleOutput outputArticle = new ArticleOutput();
			outputArticle.articleOutput(article);
		}
		else{
			System.out.println("There are no wrong words in the input file.\n");
		}
		System.out.println("The grade of the input article is '" +analyzer.grading()+ "'. ");
			
	}
}